﻿using System.Windows;
using System.Windows.Controls;

namespace Socium.Testings.Sociometric {
	/// <summary>
	/// Interaction logic for TableView.xaml
	/// </summary>
	public partial class TableView {
		public TableView() {
			InitializeComponent();
		}

		#region UpdateGrid()

		void GridLoaded(object sender, RoutedEventArgs e) {
			UpdateGrid();
		}

		void UserControlDataContextChanged(object sender, DependencyPropertyChangedEventArgs e) {
			UpdateGrid();
		}

		void UpdateGrid() {
			var grid = UiHelper.FindChild<Grid>(this, "_grid");
			if (grid == null) {
				return;
			}

			grid.ColumnDefinitions.Clear();
			grid.RowDefinitions.Clear();

			var view_model = DataContext as ProcedureViewModel;
			if (view_model == null) {
				return;
			}

			var dimension = view_model.Dimension;
			for (var i = 0; i < dimension; i++) {
				grid.ColumnDefinitions.Add(new ColumnDefinition {Width = GridLength.Auto});
				grid.RowDefinitions.Add(new RowDefinition {Height = GridLength.Auto});
			}
		}

		#endregion

	}
}
